package ensib.sti.ssu.activities;

import java.util.ArrayList;

import ensib.sti.ssu.DAO.BlocNoteDAO;
import ensib.sti.ssu.beans.BlocNote;
import android.app.Activity;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;

public class SearchActivity extends Activity {
	private BlocNoteDAO dao;
	private ArrayList<BlocNote> result;

	@Override
    public void onCreate(Bundle savedInstanceState) {
		  dao=new BlocNoteDAO(getApplicationContext());
		  result=new ArrayList<BlocNote>();
        handleIntent(getIntent());
    }

    @Override
    protected void onNewIntent(Intent intent) {
        
        handleIntent(intent);
    }

    private void handleIntent(Intent intent) {

        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            String query = intent.getStringExtra(SearchManager.QUERY);
            //use the query to search your data somehow
          dao.open();
          ArrayList<BlocNote> l=(ArrayList<BlocNote>) dao.findAll();
          dao.close();
          if(l!=null){
        	    result.clear();
        	  for (BlocNote blocNote : l) {
				if(blocNote.getNomTache().trim().toLowerCase().contains(query.trim().toLowerCase()))
					result.add(blocNote);
			}
          }
        }
    }

}
